import { ElMessage } from 'element-plus'
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

export const useDigAssetStore = defineStore('digAsset', () => {
  const brdList = ref([]) // 面包屑导航 [{id: '', name:'', type:''}] type: project, path
  const len = computed(() => brdList.value?.length)
  const brdId = computed(() => len.value ? brdList.value[len.value - 1].id : '')
  const brdType = computed(() => len.value ? brdList.value[len.value - 1].type : '')
  const isProject = computed(() => brdType.value === 'project')
  const isPath = computed(() => brdType.value === 'path')

  function brdHandle(data) {
    const i = brdList.value.findIndex(v => v.id === data.id)
    if (i === -1) return
    brdList.value = brdList.value.slice(0, i + 1)
  }
  
  function checkLen() {
    if (len.value >= 6) {
      ElMessage.warning('文件夹嵌套层数不可过多')
      return false
    }
    return true
  }

  return {
    brdList,
    len,
    brdId,
    brdType,
    isProject,
    isPath,
    brdHandle,
    checkLen,
  }
})

